# encoding = utf-8

import numpy as np

array = np.arange(3, 15)
print("array=", array)
print("array[2]=", array[2])
array = np.arange(3, 15).reshape((3, 4))
print("array=", array)
print("array[2]=", array[2])
print("array[2][2]=", array[2][2])
print("array[2,2]=", array[2, 2])
print("array[2, 0:2]=", array[2, 0:2])

for row in array:
    print(row)

for column in array.T:
    print(column)

print("array.flatten()=", array.flatten())  # flatten是一个展开性质的函数，将多维的矩阵进行展开成1行的数列

for item in array.flat:  # flat是一个迭代器，本身是一个object属性。
    print(item)

A = np.array([1, 1, 1])
B = np.array([2, 2, 2])
result = np.vstack((A, B))
print("vstack((A, B)=", result)
result = np.hstack((A, B))
print("hstack((A, B))=", result)


print("A[np.newaxis, :]=", A[np.newaxis, :])
print(A[np.newaxis, :].shape)
print("A[:, np.newaxis]=", A[:, np.newaxis])
print(A[:, np.newaxis].shape)

A = np.array([1, 1, 1])[:, np.newaxis]
B = np.array([2, 2, 2])[:, np.newaxis]
C = np.vstack((A, B))  # vertical stack
D = np.hstack((A, B))  # horizontal stack

print("D=", D)
print("A.shape=", A.shape, "D.shape=", D.shape)


C = np.concatenate((A, B, B, A), axis=0)
print("C=", C, "c.shape=", C.shape)

